package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Return implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书！");
        System.out.println("输入要归还的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int ret = bookList.getUsedSize();
        for (int i = 0; i < ret; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed()){
                    book.setBorrowed(false);
                    System.out.println("还书成功！");
                    return;
                }else {
                    System.out.println("已经归还该书！");
                    return;
                }
            }
        }
        System.out.println("没有这本书！无法归还！");
    }
}
